package com.huifaapp.mall.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.RedBagAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.RedBagBean;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

public class RedbagActivity extends AppCompatActivity {

    private ImageView Imback;
    private RecyclerView XvRedbag;
    private List<RedBagBean.DataBean>redbags;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_redbag);
        initView();

    }

    private void initView() {
        Imback = (ImageView) findViewById(R.id.iv_redbak_back);
        XvRedbag = (RecyclerView) findViewById(R.id.xv_redbag);
        Imback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        OkHttpUtils.get().url(ApiManager.BASE_NIUPAI_URL+"users/mycoupon")
                //token=2017121117473013488a1208548b1f422cb1bcbe4fc56c9501&appId=5B489793-3521-4043-95C4-9F98C6B02E47")
                .addParams("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN))
                .addParams("appId", AUniqueIdentifier.getDeviceId(RedbagActivity.this))
                .build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                RedBagBean redBagBean = gson.fromJson(response,RedBagBean.class);
                redbags = redBagBean.getData();
                RedBagAdapter redBagAdapter = new RedBagAdapter(RedbagActivity.this,redbags);
                XvRedbag.setLayoutManager(new LinearLayoutManager(RedbagActivity.this));
                XvRedbag.setAdapter(redBagAdapter);
            }
        });
    }
}
